﻿Namespace DoFactory.GangOfFour.Factory.Structural
    ''' <summary>
    ''' MainApp startup class for Structural
    ''' Factory Method Design Pattern.
    ''' </summary>
    Public Class MainApp
        ''' <summary>
        ''' Entry point into console application.
        ''' </summary>
        Public Shared Sub Main()
            ' An array of creators
            Dim creators As Creator() = New Creator(1) {}

            creators(0) = New ConcreteCreatorA()
            creators(1) = New ConcreteCreatorB()

            ' Iterate over creators and create products
            For Each creator As Creator In creators
                Dim product As Product = creator.FactoryMethod()
                Console.WriteLine("Created {0}", product.[GetType]().Name)
            Next

        End Sub

    End Class

    ''' <summary>
    ''' The 'Product' abstract class
    ''' </summary>
    MustInherit Class Product

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class ConcreteProductA
        Inherits Product

    End Class

    ''' <summary>
    ''' A 'ConcreteProduct' class
    ''' </summary>
    Class ConcreteProductB
        Inherits Product

    End Class

    ''' <summary>
    ''' The 'Creator' abstract class
    ''' </summary>
    MustInherit Class Creator
        Public MustOverride Function FactoryMethod() As Product
    End Class

    ''' <summary>
    ''' A 'ConcreteCreator' class
    ''' </summary>
    Class ConcreteCreatorA
        Inherits Creator

        Public Overrides Function FactoryMethod() As Product

            Return New ConcreteProductA()

        End Function

    End Class

    ''' <summary>
    ''' A 'ConcreteCreator' class
    ''' </summary>
    Class ConcreteCreatorB
        Inherits Creator

        Public Overrides Function FactoryMethod() As Product
            Return New ConcreteProductB()
        End Function

    End Class

End Namespace
